<?php
namespace backend\components;
use common\models\AdminModel;
use common\models\sys\SysSetting;
use Yii;
use yii\rbac\Rule;
class SettingRule extends Rule
{
    public $name = 'setting';
    /**
     * @param string|integer $user 当前登录用户的uid
     * @param Item $item 所属规则rule，也就是我们后面要进行的新增规则
     * @param array $params 当前请求携带的参数.
     * @return true或false.true用户可访问 false用户不可访问
     */
    public function execute($user, $item, $params)
    {
        $id = isset($params['id']) ? $params['id'] : null;
        if (!$id) {
            return false;
        }
        $model = SysSetting::findOne($id);
        if (!$model) {
            return false;
        }
        $username = Yii::$app->user->identity->username;
        $role = Yii::$app->user->identity->role;
        $userid = Yii::$app->user->id;
        if ($role == 'Admin' || $userid == $model->canuser) {
            return true;
        }
        return false;
    }
}